Use case: DMA2D transfer interrupt mode

Sequence diagram

DMA2D transfer interrupt mode.

@startuml
' To add a number by line
'autonumber

' Fix order of each column
participant "Application" as user
participant "DMA2D Driver" as dma2d
participant "DMA2D IRQ" as irq
participant "HW" as hw

== DMA2D Initialization and Configuration ==
user -> dma2d : HAL_DMA2D_Init()
dma2d --> user : HAL_OK or HAL_INVALID_PARAM
user -> dma2d : HAL_DMA2D_ConfigLayer()
dma2d --> user :
== DMA2D Transfer Process ==
user -> dma2d : HAL_DMA2D_Start_IT()
dma2d --> user :
hw -> irq : Interrupt
irq -> dma2d : HAL_DMA2D_IRQHandler()
dma2d -> user : Transfer complete or transfer error callback

@enduml

Code snippet

HAL1

HAL2

const uint32_t RGB888_Tab[256] = { .
                                   .
                                   .};
uint32_t RGB888_result[1024];

DMA2D_HandleTypeDef hdma2d;




/* DMA2D init configuration */
hdma2d.Instance = DMA2D;

hdma2d.Init.Mode = DMA2D_M2M_PFC;
hdma2d.Init.ColorMode = DMA2D_OUTPUT_RGB888;
hdma2d.Init.RedBlueSwap = DMA2D_RB_REGULAR;
hdma2d.Init.OutputOffset = 0x0;
hdma2d.Init.AlphaInverted = DMA2D_REGULAR_ALPHA;
hdma2d.Init.BytesSwap = DMA2D_BYTES_SWAP;

hdma2d.XferCpltCallback  = HAL_DMA2D_CL_TransferCpltCallback;
hdma2d.XferErrorCallback = HAL_DMA2D_CL_XferErrorCallback;

/* DMA2D layer configuration */

hdma2d.LayerCfg[DMA2D_FOREGROUND_LAYER].InputColorMode = DMA2D_INPUT_ARGB4444;
hdma2d.LayerCfg[DMA2D_FOREGROUND_LAYER].RedBlueSwap = DMA2D_RB_REGULAR;
hdma2d.LayerCfg[DMA2D_FOREGROUND_LAYER].InputOffset = 0;
hdma2d.LayerCfg[DMA2D_FOREGROUND_LAYER].AlphaMode = DMA2D_NO_MODIF_ALPHA;
hdma2d.LayerCfg[DMA2D_FOREGROUND_LAYER].InputAlpha = 0xFF;
hdma2d.LayerCfg[DMA2D_FOREGROUND_LAYER].AlphaInverted = DMA2D_REGULAR_ALPHA;




HAL_DMA2D_Init(&hdma2d);


HAL_DMA2D_ConfigLayer(&hdma2d, DMA2D_FOREGROUND_LAYER);
HAL_DMA2D_Start_IT(&hdma2d, (uint32_t)&RGB888_Tab,
                   (uint32_t)&RGB888_result, 130, 120);
const uint32_t RGB888_Tab[256] = { .
                                   .
                                   .};
uint32_t RGB888_result[1024];

hal_dma2d_handle_t hdma2d;

/* DMA2D initialization */
HAL_DMA2D_Init(&hdma2d, HAL_DMA2D);

/* DMA2D output configuration */

p_config.output.p_dest = (void *)&RGB888_result;

p_config.output.color_mode = HAL_DMA2D_OUTPUT_COLOR_RGB888;

p_config.output.offset = 0x0;





/* DMA2D input configuration */
p_config.input.p_src = (void const*) (uint32_t)&RGB888_Tab;
p_config.input.color_mode = HAL_DMA2D_INPUT_COLOR_ARGB4444;

p_config.input.offset = 0;
p_config.input.alpha_mode = HAL_DMA2D_INPUT_ALPHA_NO_MODIF;
p_config.input.alpha_value = 0xFF;


p_config.width = 130;
p_config.height = 120;


HAL_DMA2D_RegisterXferCpltCallback(&hdma2d, HAL_DMA2D_TransferComplete);
HAL_DMA2D_RegisterErrorCallback(&hdma2d, HAL_DMA2D_TransferError);
HAL_DMA2D_SetConfigMemCopyPFC(&hdma2d, &p_config);
HAL_DMA2D_Start_IT(&hdma2d);

Key changes

  1. In HAL2, transfer configuration is performed with a dedicated function (for example, HAL_DMA2D_SetConfigMemCopyPFC()) before starting the transfer.

  2. HAL2 provides dedicated registration APIs for the transfer-complete and error callbacks.